package com.example.dubbo.consumer.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.dubbo.consumer.entity.Order;
import com.example.dubbo.consumer.mapper.OrderMapper;
import com.example.dubbo.dto.OrderDto;
import com.example.dubbo.service.OrderService;
import com.example.dubbo.service.StorageService;
import io.seata.spring.annotation.GlobalTransactional;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * @author zxs
 * @since 2021/5/31
 */
@Service
public class ConsumerOrderService extends ServiceImpl<OrderMapper, Order> {

    @DubboReference(check = false)
    private StorageService storageService;

    @DubboReference(check = false)
    private OrderService orderService;

    @GlobalTransactional(timeoutMills = 300000)
    public Long createOrder(String userId, String orderType) {
        OrderDto dto = new OrderDto();
        dto.setContent("订单");
        dto.setOrderType(orderType);
        dto.setUserId(userId);
        Long id = orderService.create(dto);
        storageService.purseStorage();
        return id;
    }
}
